package com.invoicing.Service;

import com.invoicing.dao.CommodityMapper;
import com.invoicing.entity.Commodity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommodityService {
    @Autowired
    private CommodityMapper commodityMapper;

    public Commodity findCommodity(int id){ return commodityMapper.selectById(id);}

    public int updateName(int id,String name){ return commodityMapper.updateName(id,name);}

    public int updateTypeId(int id,int typeId){ return commodityMapper.updateTypeId(id,typeId);}

    public int updateStock(int id,int stock){return commodityMapper.updateStock(id,stock);}

    public int updateAlert(int id,int alert){return commodityMapper.updateAlert(id,alert);}

    public int updatePrice(int id,float price){return commodityMapper.updatePrice(id,price);}

    public int updateDiscount(int id,float discount){return commodityMapper.updateDiscount(id,discount);}

    public Commodity findByName(String name){ return commodityMapper.selectByName(name);}

    public int insertNew(Commodity commodity){ return commodityMapper.insertCommodity(commodity);}

    public List<Commodity> listAll(){ return commodityMapper.selectAll();}



    public boolean commodityExitById(int id){
        if(this.findCommodity(id)==null){
            return false;
        }
        return true;
    }

}
